#include "libCAN_defines.h"

#ifndef CAN_DATA_PROTOCOL_H
#define CAN_DATA_PROTOCOL_H

// Called to parse received CAN data
void CAN_parse_received_data(void);

// Called to start the next data send,  including constructing the CAN data packet.
void CAN_send_next_data(void);

// Requests a data transmit and start transmission if none are running.
inline void requestRadioDataTransmit();
inline void requestControlDataTransmit();
inline void requestServoDataTransmit();
inline void requestFlagsTransmit();


typedef struct tagRADIO_DATA_BITS
{
	unsigned int 	PWM				: 15;
	unsigned int 	servoFound		: 1;
} RADIO_DATA_BITS;

typedef union 
{
	RADIO_DATA_BITS	_;
	unsigned int	W;
} RADIO_DATA;


typedef struct tagDATA_TX_REQUEST_BITS
{
	unsigned int	tx_req_radio_data		: 1;
	unsigned int	tx_req_control_data		: 1;
	unsigned int	tx_req_servo_data		: 1;
	unsigned int	tx_req_flags_data		: 1;
	unsigned int							: 4;
} DATA_TX_REQUEST_BITS;


typedef union
{
	unsigned char			reqs;
	DATA_TX_REQUEST_BITS	_;
} DATA_TX_REQUESTS;


typedef enum
{
	CONTROL_DATA_NONE,
	CONTROL_DATA_SERVO,
	CONTROL_DATA_RADIO,
	CONTROL_DATA_AP_CONTROL,
	CONTROL_DATA_FLAGS
} CONTROL_DATA_TYPES;

#endif
